﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data.SqlClient;

namespace Db
{
    public class CinemaDb : AbstractDb
    {
        public List<Cinema> GetAllCinemas()
        {
            List<Cinema> cinemas = new List<Cinema>();
            SqlDataReader q = this.db.Query("SELECT * FROM Bif_Cinema");
            if (q.HasRows && q.Read())
            {
                while (q.Read())
                {
                    int id = q.GetInt32(q.GetOrdinal("cinema_ID"));
                    int seats = q.GetInt32(q.GetOrdinal("cinema_seatCount"));
                    string title = q.GetString(q.GetOrdinal("cinema_title"));

                    Cinema newCinema = new Cinema(id, seats, title);
                    cinemas.Add(newCinema);
                }
            }
            return cinemas;
        }

        public Cinema GetCinemaByID(int cinID)
        {
            Cinema newCinema = null;
            SqlDataReader q = this.db.Query("SELECT * FROM Bif_Cinema WHERE cinema_ID = " + cinID);
            if (q.HasRows && q.Read())
            {
                int id = q.GetInt32(q.GetOrdinal("cinema_seatCount"));
                int seats = q.GetInt32(q.GetOrdinal("cinema_seatCount"));
                string title = q.GetString(q.GetOrdinal("cinema_title"));

                newCinema = new Cinema(id, seats, title);
            }
            return newCinema;
        }

        public Cinema GetCinemaByTitle(string cinTitle)
        {
            Cinema newCinema = null;
            SqlDataReader q = this.db.Query("SELECT * FROM Bif_Cinema WHERE cinema_title = " + cinTitle);
            if (q.HasRows && q.Read())
            {
                int id = q.GetInt32(q.GetOrdinal("cinema_ID"));
                int seats = q.GetInt32(q.GetOrdinal("cinema_seatCount"));
                string title = q.GetString(q.GetOrdinal("cinema_title"));

                newCinema = new Cinema(id, seats, title);
            }
            return newCinema;
        }
    }
}
